home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4281 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.2 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help with Bug Pleeeeease!
  5. Date: 29 Jan 1996 15:18:40 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4eiogg$cbj@dawn.mmm.com>
  8. References: <tday-2801961838030001@tday.slip.netcom.com>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Tony Day (tday@netcom.com) wrote:
  13.  
  14. [ explanation and lots of code elided ]
  15.  
  16. > String String::operator+(const String & st) const
  17. > {
  18. >    String temp1;
  19. >    delete [] temp1.str;
  20. >    temp1.len = st.len+len;
  21. >    temp1.str = new char[temp1.len+1];
  22. >    strcpy(temp1.str,str);
  23. >    for (int i=len; i< temp1.len; i++)
  24. >       temp1.str[i]=st.str[i-len];
  25. >    temp1.str[temp1.len+1]='\0';
  26.                         ^^ <-- The bug is here.  Leave off the +1.
  27. >    cout << temp1.len << " length1st\n";
  28. >    return temp1;
  29. > }
  30. --
  31. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  32. 3M Company                      phone:  (612) 737-4643
  33. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  34. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  35.     But 3M speaks for me -- I did not write the following line:
  36.  
  37. Opinions expressed herein are my own and may not represent those of 3M.
  38.